home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / EBKSRC.ARJ / PCPUT2.CPP < prev    next >
C/C++ Source or Header  |  1991-07-30  |  2KB  |  85 lines

  1. /*
  2.  
  3.     pcput2.cpp
  4.     7-30-91
  5.     Write two color text strings
  6.  
  7.     Copyright 1991
  8.     John W. Small
  9.     All rights reserved
  10.     Use freely but acknowledge authorship and copyright.
  11.  
  12.     PSW / Power SoftWare
  13.     P.O. Box 10072
  14.     McLean, Virginia 22102 8072 USA
  15.  
  16.     John Small
  17.     Voice: (703) 759-3838
  18.     CIS: 73757,2233
  19.  
  20. */
  21.  
  22. #include <pcput2.hpp>
  23.  
  24. int ScrLnBuf::buf[MAX_SCR_LN_BUF];
  25.  
  26. void ScrLnBuf::set(int normattr, int highattr,
  27.     unsigned pgWidth, unsigned startColumn, int clreol,
  28.     char lineTermChar, char attrToggleChar,
  29.     unsigned tabSpacing)
  30. {
  31.     this->normattr        =  normattr;
  32.     this->highattr        =  highattr;
  33.     if (pgWidth > MAX_SCR_LN_BUF)
  34.         this->pgWidth = MAX_SCR_LN_BUF;
  35.     else
  36.         this->pgWidth = pgWidth;
  37.     this->startColumn     =  startColumn;
  38.     this->clreol          =  clreol;
  39.     this->lineTermChar    =  lineTermChar;
  40.     this->tabSpacing      =  tabSpacing;
  41.     this->attrToggleChar  =  attrToggleChar;
  42.     eolColumn             =  1;
  43.     lidx                  =  0;
  44. }
  45.  
  46. int ScrLnBuf::writebuf(const char *line)
  47. {
  48.     int toggle = 0;
  49.     int attr = (normattr << 8);
  50.     int bidx = 0;
  51.     eolColumn = 1;
  52.     if (line) for (lidx = 0; bidx < pgWidth &&
  53.         line[lidx] && line[lidx] != lineTermChar;
  54.         lidx++)
  55.         if (line[lidx] == attrToggleChar)
  56.             if (line[lidx+1] == attrToggleChar)  {
  57.                 lidx++;
  58.                 if (eolColumn++ >= startColumn)
  59.                     buf[bidx++] = attr |
  60.                     (unsigned char)
  61.                     attrToggleChar;
  62.             }
  63.             else
  64.                 if (++toggle % 2)
  65.                     attr = (highattr << 8);
  66.                 else
  67.                     attr = (normattr << 8);
  68.         else if (line[lidx] == '\t')
  69.             do {
  70.                 if (eolColumn >= startColumn)
  71.                     buf[bidx++] = attr |
  72.                     (unsigned char) ' ';
  73.             } while (eolColumn++ % tabSpacing);
  74.         else  if (eolColumn++ >= startColumn)
  75.                 buf[bidx++] = attr |
  76.                 (unsigned char) line[lidx];
  77.     if (bidx < pgWidth && clreol)  {
  78.         attr |= (unsigned char) ' ';
  79.         while (bidx < pgWidth)
  80.             buf[bidx++] = attr;
  81.     }
  82.     return bidx;
  83. }
  84.  
  85.